import request from '@/utils/request';
import { ResponseData, SUCCESS_CODE } from '@/utils/types.d';
import { StatsConfig } from './types.d';

export async function getStatsConfig(ownerId: string) {
  const res: ResponseData<StatsConfig> = await request(`/api/config/v1.0.0/stats/${ownerId}`, {
    method: 'GET',
  });
  if (res?.code === SUCCESS_CODE) return { success: true, message: '获取成功', data: res.data };
  return { success: false, message: res?.message || '获取失败', data: res?.data };
}

export async function editStatsConfig(data: StatsConfig) {
  const res: ResponseData<StatsConfig> = await request(`/api/config/v1.0.0/stats/edit`, {
    method: 'POST',
    data,
  });
  if (res?.code === SUCCESS_CODE) return { success: true, message: '修改成功', data: res.data };
  return { success: false, message: res?.message || '修改失败', data: res?.data };
}
